import 'package:flutter/material.dart';
import 'package:god_logistics/pages/loginVIew/loginPage.dart';
import 'package:god_logistics/pages/tabbar.dart';
import 'package:god_logistics/utils/showToast.dart';
import 'package:god_logistics/utils/tokenManage.dart';

class allPage extends StatefulWidget {
  const allPage({super.key});

  @override
  State<allPage> createState() => _allPageState();
}

class _allPageState extends State<allPage> {
  // 检查token
  Future<String?> _checkToken() async {
    final tokenManager = TokenManager();
    await tokenManager.init();
    return tokenManager.getToken();
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _checkToken();
  }

  @override
  Widget build(BuildContext context) {
    return FutureBuilder(
      future: _checkToken(),
      builder: (context, snapshot) {
        if (snapshot.connectionState == ConnectionState.waiting) {
          return Center(child: CircularProgressIndicator());
        }
        if (snapshot.hasError) {
          return Center(child: Text("加载失败"));
        }
        final token = snapshot.data as String?;
        if (token == null || token.isEmpty) {
          return Loginpage();
        }
        return tabpage();
      },
    );
  }
}
